namespace Resharper.Abstractions.CodeDom.Statements.TryStatements
{
  using System.Collections.Generic;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;

  /// <summary>Defines the <see cref="TryStatement"/> class.</summary>
  public class TryStatement : Statement
  {
    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="TryStatement"/> class.</summary>
    /// <param name="statement">The statement.</param>
    internal TryStatement([NotNull] ITryStatement statement) : base(statement)
    {
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the catches.
    /// </summary>
    public IEnumerable<CatchClause> Catches
    {
      get
      {
        var catchClauses = this.InternalTryStatement.Catches;
        if (catchClauses == null)
        {
          yield break;
        }

        foreach (var catchClause in catchClauses)
        {
          yield return new CatchClause(catchClause);
        }
      }
    }

    /// <summary>
    /// Gets the internal for statement.
    /// </summary>
    [NotNull]
    internal ITryStatement InternalTryStatement
    {
      get
      {
        return (ITryStatement)this.InternalStatement;
      }
    }

    #endregion
  }
}